//
//  GW_Request.m
//  PaiLeXiongProject
//
//  Created by 小獾科技 on 2017/9/25.
//  Copyright © 2017年 小獾科技. All rights reserved.
//

#import "GW_Request.h"

@implementation GW_Request

static GW_Request *gInstance = nil;

+ (GW_Request *)sharedInstance {
    
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        gInstance = [[self alloc] init];
    });
    
    return gInstance;
}

- (instancetype)init {
    
    self = [super init];
    if (self) {
        
        //网络监控
        //要监控网络连接状态，必须要先调用单例的startMonitoring方法
        [[AFNetworkReachabilityManager sharedManager] startMonitoring];
        [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
            //status:
            //AFNetworkReachabilityStatusUnknown          = -1,  未知
            //AFNetworkReachabilityStatusNotReachable     = 0,   未连接
            //AFNetworkReachabilityStatusReachableViaWWAN = 1,   3G
            //AFNetworkReachabilityStatusReachableViaWiFi = 2,   无线连接
            switch (status) {
                case AFNetworkReachabilityStatusNotReachable:
                {
                    MESSAGE_TOAST(@"当前没有网络");
                    self.noNetwork = YES;
                    [[NSUserDefaults standardUserDefaults] setObject:@(self.noNetwork) forKey:@"noNetwork"];
                }
                    break;
                default://有网络
                {
                    self.noNetwork = NO;
                }
                    break;
            }
            
        }];
        
    }
    return self;
}



@end
